home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12347 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  60 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!mv!usenet
  3. From: ENGR@GSSI.MV.COM (Michael Furman)
  4. Subject: Re: "free"ing classes when the "new" is inside a function
  5. Message-ID: <DoIwyp.HHw@mv.mv.com>
  6. Mime-Version: 1.0
  7. Content-Type: Text/Plain; charset=US-ASCII
  8. Organization: GSSI
  9. Date: Tue, 19 Mar 1996 16:40:00 GMT
  10. References: <4ic7a5$94u@falcon.ccs.uwo.ca>
  11. X-Newsreader: WinVN 0.99.7
  12. X-Nntp-Posting-Host: gssi.mv.com
  13.  
  14. In article <4ic7a5$94u@falcon.ccs.uwo.ca>, turnbull@canlon.physics.uwo.ca 
  15. says...
  16. >
  17. >I have code something like
  18. >
  19. >MyClass* Myfunc(){
  20. >  Class* value;
  21. >.
  22. >.
  23. >  value = new MyClass(........);        <- 1 of several possible 
  24. constructors
  25. >.
  26. >  return value;
  27. >}
  28. >
  29. >
  30. >------ in main---------
  31. >.
  32. >Class* value;
  33. >value=Myfunc();
  34. >.
  35. >
  36. >How do I free up the memory allocated to value?
  37. >delete value won't do it.
  38.  
  39. Just "delete value;"
  40. It will first call destructor for this class (if exist) and then free memory.
  41.  
  42. >
  43. >Thanks.
  44. >
  45. >David Turnbull
  46. >Department of Physics
  47. >University of Western Ontario
  48. >London, Ontario, Canada
  49. >
  50.  
  51. -- 
  52. <<< If you received it by E-mail: it is a copy of post to the newsgroup >>>
  53. ---------------------------------------------------------------
  54. Michael Furman,                       (603)893-1109
  55. Geophysical Survey Systems, Inc.  fax:(603)889-3984
  56. 13 Klein Drive - P.O. Box 97          engr@gssi.mv.com 
  57. North Salem, NH 03073-0097            71543.1334@compuserve.com
  58. ---------------------------------------------------------------
  59.  
  60.